<template>
    <div id="CompanyDialog">
        <el-dialog :title="type?'企业审核':'企业详情'" width="900px" :visible.sync="show">
            <vj-form @submit="onSubmit" :hide-foot="!type" i @close="show=false" hide-reset :style-config="{labelWidth:'160px'}"
                     :slot-idx="cfgList.length"
                     :loading="loading" class="vj-form" :cfg-list="cfgList"
                     :form-data.sync="formData"/>
        </el-dialog>
    </div>
</template>
<script lang="ts">
    import Vue, {ComponentOptions, VueConstructor} from "vue"
    import Component from 'vue-class-component'
    import {Mixins} from "vue-property-decorator";
    import {FormMixin} from "@/plugins/mixins/form";
    import {ActivityFormTB} from "@/config/table";
    import {
        ACTIVITY_FM,
        ACTIVITY_LINK_FM,
        CAPITAL_FM,
        COMPANY_FM,
        disableFMAll,
        JOB_FM,
        PIC_FM,
        TALENT_FM
    } from "@/config/form";
    import {cloneDeep, formatOptions, hookSubmit, updateCfgOption} from "vijay-util";
    import {requestByGet, requestByPost, requestByPut} from "@/utils/request";

    @Component
    export default class CompanyDialog extends Mixins(FormMixin) implements ComponentOptions<Vue> {
        name = "CompanyDialog"
        type = 0
        show = false;
        editId = null;
        formData = {};
        cfgList = [];
        @hookSubmit()
        async onSubmit() {
            const requestFn = this.editId ? requestByPut : requestByPost;
            await requestFn(`qqc/qqcBusiness/${this.editId ? 'edit' : 'add'}`, {...this.formData, id: this.editId});
            this.$message.success("操作成功！");
            this.show = false;
            this.$emit('refresh')
        }
        async initOptions() {
            const {records} = await requestByGet(`qqc/qqcProfession/list`, {pageNo: 1, pageSize: 999});
            this.cfgList = updateCfgOption(this.cfgList, "trade", formatOptions(records, "name", "id"))
        }
        initCfgList() {
            this.cfgList = disableFMAll(COMPANY_FM(this.type), true,"status", "remarks2")
        }
        open(data = {} as any, type = 0) {
            this.show = true;
            this.type = type;
            this.initCfgList();
            this.formData = cloneDeep(data);
            this.editId = data.id;
        }
        created() {
            this.initOptions();
        }
    }
</script>

<style scoped lang="scss">
    @import "~assets/common.scss";
    #CompanyDialog {
    }
</style>
